package com.ruoyi.system.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.vo.Approval.ApprovalManagement.ApprovalManagementVO;
import com.ruoyi.system.domain.vo.Approval.ApprovalManagement.Apporver;
import com.ruoyi.system.service.IApprovalManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/approval/approvalManagement")
public class ApprovalManagementController extends BaseController {

    @Autowired
    private IApprovalManagementService approvalManagementService;

    @GetMapping("/list")
    public TableDataInfo getApprovalList(
            @RequestParam(required = false) String status,
            @RequestParam(required = false) String typeName) {
//        startPage();
        List<ApprovalManagementVO> approvalList = approvalManagementService.getApprovalList(status, typeName);
        return getDataTable(approvalList);
    }

    //同意
    @PutMapping("/agree")
    public AjaxResult agree(@RequestParam("id") int id) {
        int result = approvalManagementService.agree(id);
        if (result > 0) {
            return success(result);
        } else {
            return error("操作失败");
        }
    }
    //拒绝
    @PutMapping("/refuse")
    public AjaxResult refuse(@RequestParam("id") int id) {
        int result = approvalManagementService.refuse(id);
        if (result > 0) {
            return success(result);
        } else {
            return error("操作失败");
        }
    }
    //转交
    @PutMapping("/transfer")
    public AjaxResult transfer(@RequestParam("id") int id, @RequestParam("nextId") int nextId) {
        int result = approvalManagementService.transfer(id, nextId);
        if (result > 0) {
            return success(result);
        } else {
            return error("操作失败");
        }
    }

    @GetMapping("/approvers")
    public TableDataInfo selectApprovers() {
        List<Apporver> approvers = approvalManagementService.selectApprovers();
        return getDataTable(approvers);
    }

}
